/**
 * Created by dongp on 2018/1/18.
 */
//系统时间显示
setInterval("document.getElementById('nowTime').innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
var setting = {
    data: {
        simpleData: {
            enable: true
        }
    },
    view: {
        selectedMulti: false
    },
    callback: {
        onClick:function(e, id, node){
            var zTree = $.fn.zTree.getZTreeObj("menuTree");
            if(node.isParent) {
                zTree.expandNode();
            } else {
                addTabs(node.name, node.file,node.id);
            }
        }
    }
};

var zNodes =[
    { id:1, pId:0, name:"系统管理", open:true},
    //{ id:11, pId:1, name:"应用管理", file:"view/app$list"},
    { id:12, pId:1, name:"角色管理", file:"/view/biz/role/roleList.html"},
    { id:13, pId:1, name:"用户管理", file:"/view/biz/user/userList.html"},
    { id:14, pId:1, name:"资源管理", file:"/view/biz/resource/resourceList.html"}
    //{ id:14, pId:1, name:"用户组管理", file:"view/usergroup$list"},
    //{ id:15, pId:1, name:"城市管理", file:"view/city$list"},
    //{ id:16, pId:1, name:"在线用户", file:"view/user$online"},
    //{ id:17, pId:1, name:"黑白名单维护", file:"view/iplist$list"},
    //{ id:17, pId:1, name:"登录日志", file:"view/userLog$list"}
];

$(function() {
    $.fn.zTree.init($("#menuTree"), setting, zNodes);
    var zTree = $.fn.zTree.getZTreeObj("menuTree");

    //中间部分tab
    $('#tabs').tabs({
        border:false,
        fit:true,
        onSelect: function(title, index){
            var treeNode = zTree.getNodeByParam("name", title, null);
            zTree.selectNode(treeNode);
        }
    });

    $('.index_panel').panel({
        width:300,
        height:200,
        closable:true,
        minimizable:true,
        title: 'My Panel'
    });

});

//添加一个选项卡面板
function addTabs(title, url, id,icon){
    if(!$('#tabs').tabs('exists', title)){
        $('#tabs').tabs('add',{
            title:title,
            content:'<iframe src="'+url+'" frameBorder="0" border="0" scrolling="no" style="width: 100%; height: 100%;" id=iframe'+id+'/>',
            closable:true
        });
    } else {
        $('#tabs').tabs('select', title);
    }
}